<template>
    <div class="manuscript_root">
        <div class="manuscript_video" @click="PlayVideo(id)">
            <el-image style="width: 9.8rem; height: 100%" :src="posterDefault" :fit="fits" lazy />
            <div class="manuscript_video_play">
                <VideoPlay class="video_info" />
            </div>
        </div>
        <div class="manuscript_info">
            <h4>标题:{{ title }}</h4>
            <span class="topTwo">简介:{{ subscribe }}</span>
            <div class="info_box">
                <span class="info">作者:{{ author }}</span>
                <span class="info">上传日期:{{ date }}</span>
                <span class="info">分区:{{ GetPartition }}</span>
                <span class="info" v-if="history">点赞数:{{ like }}</span>
            </div>
        </div>
        <div class="manuscript_status">
            <span class="status">当前状态:
                <el-text :type="statusShow">{{ statusText }}</el-text>
            </span>
        </div>
        <div class="manuscript_handle">
            <el-link type="primary" v-if="!history" @click="AcceptTrend()">
                <slot name="Accept">审核通过</slot>
            </el-link>
            <el-link type="danger" v-else @click="OffShelf()">
                <slot name="offShelf">下架稿件</slot>
            </el-link>
            <el-link type="danger"  @click="RejectTrend()">
                <slot name="Reject">驳回稿件</slot>
            </el-link>
            
        </div>
    </div>
</template>

<script setup>
import { ref, computed, toRefs } from 'vue'
import devURL from '../Config/NetBaseConfig.js'
const fits = ['fill', 'contain', 'cover', 'none', 'scale-down']
//控制颜色
let textColor = ref('primary')

let props = defineProps({
    id: {
        type: String,
        required: true,
    },
    videoPoster: "",
    videoUrl: "",
    title: "",
    subscribe: "",
    author: "",
    date: "",
    partition: "",
    like: 0,
    status: '',
    history: {
        type: Boolean,
        default: false,
    }
})

let emits = defineEmits(['PlayerVideo', 'Accept', 'Reject', 'OffShelf'])

let data = computed(() => {
    return toRefs(props)
})

//测试模式下设置视频图片
let posterDefault = computed(() => {
    if (data.value.videoPoster.value === "" || data.value.videoPoster.value === null) {
        return new URL("../assets/Image/temp.png", import.meta.url).pathname
    }
    let url = data.value.videoPoster.value
    let result = url.substring(url.lastIndexOf("/video/"));
    return `${devURL}${result}`
})
//* 投放分区(0-默认,1-动漫,2-游戏,3-音乐)
let GetPartition = computed(() => {
    let res = ''
    switch (props.partition) {
        case 0:
            res = '动漫'
            break;
        case 1:
            res = '游戏'
            break;
        case 2:
            res = '音乐'
            break;
        default:
            res = '默认'
            break;
    }
    return res
})


let videoURLTransform = computed(() => {
    if (data.value.videoUrl.value === "" || data.value.videoUrl.value === null) {
        return new URL("../assets/Image/temp.png", import.meta.url).pathname
    }
    let url = data.value.videoUrl.value
    let result = url.substring(url.lastIndexOf("/video/"));
    return `${devURL}${result}`
})

//通过当前稿件状态改变颜色
let statusShow = computed(() => {
    textColor.value = 'primary'
    //TODO:显示有误请找这
    // switch (data.value.status) {
    //     case 0:
    //         textColor.value = 'info'
    //         break;
    //     case 1:
    //         textColor.value = 'success'
    //         break;
    //     case 2:
    //         textColor.value = 'error'
    //         break;
    //     default:
    //         textColor.value = 'primary'
    //         break;
    // }
    switch (props.status) {
        case 0:
            textColor.value = 'info'
            break;
        case 1:
            textColor.value = 'success'
            break;
        case 2:
            textColor.value = 'error'
            break;
        default:
            textColor.value = 'primary'
            break;
    }
    return textColor.value
})

let statusText = computed(() => {
    let status = data.value.status.value
    let text = '审核中'
    switch (status) {
        case 0:
            text = '审核中'
            break;
        case 1:
            text = '审核通过'
            break;
        case 2:
            text = '已被驳回'
            break;
        default:
            text = '审核中'
            break;
    }
    return text
})



//告知父组件播放视频
const PlayVideo = () => {
    let videoUrl = videoURLTransform.value
    let videoPoster = posterDefault.value
    emits('PlayerVideo', { videoPoster, videoUrl })
}

const AcceptTrend = () => {
    emits('Accept', props.id)
}

const RejectTrend = () => {
    emits('Reject', props.id)
}

const OffShelf = () => {
    emits('OffShelf', props.id)
}

</script>

<style lang='less' scoped>
.manuscript_root {
    padding: 0 0.5rem 0 0.5rem;
    width: 100%;
    height: 16vh;
    border-bottom: 1px solid #ccc;
    display: flex;

    .manuscript_video {
        position: relative;

        .manuscript_video_play {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);

            .video_info {
                width: 2rem;
                height: 2rem;
                color: #ccc;
            }
        }
    }

    .manuscript_info {
        flex: 2;
        margin-left: 1rem;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: start;

        .topTwo {
            font-size: 16px;
        }

        .info_box {
            display: flex;
            justify-content: start;
            align-items: start;
            flex-wrap: nowrap;
        }
    }

    .info {
        font-size: 16px;
        color: #ccc;
        margin-right: 0.5rem;
    }

    .manuscript_status {
        height: 100%;
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;

        .status {
            font-size: 0.8rem;
        }
    }

    .manuscript_handle {
        height: 100%;
        display: flex;
        margin-right: 1rem;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        user-select: none;
        cursor: pointer;

        .handle_item {
            display: inline-block;
            font-size: 18px;

            &:hover {
                text-decoration: underline;
            }
        }
    }
}
</style>